#ifndef _DS1307_H
#define _DS1307_H

#include "public.h"
#include "iic.h"

#define IIC_Stop(void) iic_stop(void)

#define IIC_Ack(void) iic_ack(void)

#define IIC_NoAck(void) iic_nack(void)

#define IIC_WaitAck(void) iic_wait_ack(void)

#define IIC_WriteByte(dat) iic_write_byte(dat)

#define IIC_ReadByte(ack) iic_read_byte(ack)


#define WRITE_CMD				0x00
#define READ_CMD				0x01
#define DEV_ADDR                0xD0//器件地址，0x68<<1
#define REG_SEC 0x00
#define REG_MIN 0x01
#define REG_HOUR 0x02
#define REG_DAY 0x03
#define REG_DATE 0x04
#define REG_MONTH 0x05
#define REG_YEAR 0x06
#define REG_CTRL 0x07

	
extern u8 gDS1302_TIME[7];

void DS1307_Init(void);

void DS1307_Read_Time(void);

void DS1307_OutLow(void);

void DS1307_OutHigh(void);

void DS1307_SetSqureWaveFreq(u8 rate);

void DS1307_SQWDisable(void);

void DS1307_SQWEnable(void);

void DS1307_ClearHaltFlag(void);

void DS1307_SetHaltFlag(void);

void DS1307_SetSecond(u8 sec);

void DS1307_SetMinute(u8 min);

void DS1307_SetHour(u8 hour);

void DS1307_SetDate(u8 date);

void DS1307_SetMonth(u8 month);

void DS1307_SetDay(u8 day);

void DS1307_SetYear(u16 year);

u8 DS1307_GetSecond(void);

u8 DS1307_GetMinute(void);

u8 DS1307_GetAMPM(void);

void DS1307_SetAMPM(u8 dat);

void DS1307_SetHourMode(u8 mode);

u8 DS1307_GetHourMode(void);

u8 DS1307_GetHour(void);

u8 DS1307_GetDate(void);

u8 DS1307_GetMonth(void);

u8 DS1307_GetDay(void);

u16 DS1307_GetYear(void);

u8 DS1307_ReadReg(u8 addr);

u8 DecToBCD(u8 dec);

u8 BCDToDec(u8 bcd);

u8 DS1307_ReadHaltFlag(void);

void DS1307_WriteReg(u8 addr, u8 dat);

#endif
